package org.eda.actividad4;

public class ColaArray<T> 
{
    private final int maxSize = 100;
    private T[] array;
    private int first;
    private int rear;
    private int nItems;

    public ColaArray() 
	{
	    this.array = (T[])(new Object[maxSize]);
	    this.first = 0;
	    this.rear = -1;
	    this.nItems = 0;
	}

    public T first()
    {
    	return array[first];
    }
    
	public boolean isEmpty()
	{
		return nItems == 0;
	}

	public void insert(T elem) 
	{
	    	if(rear == maxSize-1)
	    	{
	    		rear = rear-1;
	    	}
	    	array[++rear] = elem;
	    	nItems++;
	}

	public T remove() 
	{
	    T elem;
	    elem = array[first++];
	    if (first == maxSize)
	    {
	    	first = 0;
	    }
	    nItems--;
	    return elem;
	}

	public int size() 
	{
	    return nItems;
	}
}